﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using TMDT_Nhom1A.BUS;
using TMDT_Nhom1A.DTO;
using System.Collections.Generic;

namespace TMDT_Nhom1A.Customer
{
    public partial class ThanhToan_Buoc1_SendMail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //lay don hang tu database va gui mail xac nhan cho khach hang
                string userID = "";
                if (Session["UserID"].ToString() != "")
                {
                    userID = Session["UserID"].ToString();
                    Cart cart = OrderB2B_BUS.GetSaveDetailOrderB2B(userID);

                    
                    //gui mail cho khach hang
                    //lay thong tin khach hang

                    List<Customer_DTO> customerList = Customer_BUS.getCustomerInfoByUserID(int.Parse(userID));
                    Customer_DTO customerInfo = customerList.First();


                    //get host name;
                    string path = "";
                    HttpContext context = HttpContext.Current;
                    path = String.Format("{0}://{1}/", context.Request.Url.Scheme, context.Request.Url.Host);
                    bool sendMailResult = utils.User.sendMailToCustomerB2B(cart,customerInfo.Email,path);
                    if (sendMailResult == true)
                    {
                        Session["Step"] = 1;
                        Success.Visible = true;
                        failure.Visible = false;
                    }
                    else
                    {
                        failure.Visible = true;
                        Success.Visible = false;
                    }
                }
                
               

            }
        }
    }
}
